<template>
  <div class="hzy_add">
    <!-- 增加员工表格 -->
    <el-dialog
      title="增加员工"
      :visible.sync="dialogVisible"
      width="1000px"
      :before-close="handleClose"
    >
      <span>
        <el-form :inline="true" class="demo-form-inline" :model="employeeAdd">
          <el-form-item label="员工编码">
            <el-input v-model="employeeAdd.nameId"></el-input>
          </el-form-item>
          <el-form-item label="用户名">
            <el-input v-model="employeeAdd.userName"></el-input>
          </el-form-item>
          <el-form-item label="角色名称">
            <el-select placeholder="请选择" v-model="employeeAdd.jiaoSe">
              <el-option
                v-for="item in jiaoseGroup"
                :key="item.jiaoseid"
                :value="item.jiaoseid"
              ></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="员工姓名">
            <el-input v-model="employeeAdd.name"></el-input>
          </el-form-item>
          <el-form-item label="身份证号">
            <el-input v-model="employeeAdd.idCard"></el-input>
          </el-form-item>
          <el-form-item label="联系电话">
            <el-input v-model="employeeAdd.phone"></el-input>
          </el-form-item>
          <el-form-item label="所属门店">
            <el-select placeholder="请选择" v-model="employeeAdd.mendian">
              <el-option
                v-for="item in fendianGroup"
                :key="item.fendianid"
                :value="item.fendianid"
              ></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="所属分组">
            <el-select placeholder="请选择" v-model="employeeAdd.zuMing">
              <el-option
                v-for="item in fenzuGroup"
                :key="item.fenzuid"
                :value="item.fenzuid"
              ></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="在职状态：">
            <el-radio v-model="employeeAdd.zhuangTai" :label="true"
              >在职</el-radio
            >
            <el-radio v-model="employeeAdd.zhuangTai" :label="false"
              >离职</el-radio
            >
          </el-form-item>
        </el-form>
      </span>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取消</el-button>
        <el-button :plain="true" type="primary" @click="SaveMsg"
          >保存</el-button
        >
      </span>
    </el-dialog>
  </div>
</template>

<script>
import { addEmployeeApi } from "@/http/employeeListApi";
export default {
  name: "AddEmployee",
  props: ["isShowAdd"],
  mounted() {
    this.dialogVisible = this.isShowAdd;
  },
  watch: {
    dialogVisible: function () {
      if (!this.dialogVisible) {
        this.$emit("closeAdd");
      }
    },
  },
  data() {
    return {
      dialogVisible: false,
      employeeAdd: {
        nameId: "",
        userName: "",
        jiaoSe: "",
        name: "",
        idCard: "",
        phone: "",
        mendian: "",
        zuMing: "",
        zhuangTai: "",
      },
      addList: {},
      jiaoseGroup: [
        // 角色名称
        {
          jiaoseid: "销售组",
        },
        {
          jiaoseid: "采购组",
        },
      ],
      fendianGroup: [
        // 所属门店
        {
          fendianid: "望京分店",
        },
        {
          fendianid: "王府井分店",
        },
      ],
      fenzuGroup: [
        {
          fenzuid: "A组",
        },
        {
          fenzuid: "B组",
        },
      ],
    };
  },
  methods: {
    handleClose(done) {
      this.$confirm("确认关闭？")
        .then(() => {
          done();
        })
        .catch(() => {});
    },
    AddInfo() {
      // 新增页面显示
      this.$emit("addClick");
      this.dialogVisible = true;
    },
    SaveMsg() {
      // 保存新增员工数据
      this.addList = this.employeeAdd;
      this.dialogVisible = false;
      this.$emit("getInit"); // 重新渲染
      console.log(this.employeeAdd.zhuangTai);
      addEmployeeApi(this.addList)
        .then((res) => {
          this.employeeAdd = {}; // 制空
          console.log("新增成功", res);
          this.$message({
            message: "保存成功",
            type: "success",
          });
        })
        .catch((err) => {
          console.log("新增失败", err);
        });
    },
  },
};
</script>